﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QLThuVien
{
    class Sach
    {
        string masach, tensach, maloai, mann,mancc;
        int gia,lanxuatban,namxuatban;
        string manxb,mavitri,matg;        
        

        #region cac phuong thuc set
        public Sach(){}

        public void set_masach(string masach)
        {
            this.masach = masach;        
        }
       
        public void set_tensach(string tensach)
        {
            this.tensach = tensach;
        }

        public void set_mancc(string mancc)
        {
            this.mancc = mancc;
        }

        public void set_mavitri(string mavitri)
        {
            this.mavitri = mavitri;
        }

        public void set_maloai(string maloai)
        {
            this.maloai = maloai;
        }
                
        public void set_mangonngu(string mann)
        {
            this.mann = mann;
        }

        public void set_gia(int gia)
        {
            this.gia = gia;
        }
        
        public void set_manhaxuatban(string manxb)
        {
            this.manxb = manxb;
        }

        public void set_namxuaban(int namxuatban)
        {
            this.namxuatban = namxuatban;
        }

        public void set_lanxuatban(int lanxuatban)
        {
            this.lanxuatban = lanxuatban;
        }

        public void set_matacgia(string matg)
        {
            this.matg = matg;
        }


#endregion

        #region cac phuong thuc get
        public string get_masach()
        {
            return masach;
        }

        public string get_tensach()
        {
            return tensach;
        }

        public string get_mancc()
        {
            return mancc;
        }

        public string get_mavitri()
        {
            return mavitri;
        }
        public string get_maloai()
        {
            return maloai;
        }
                
        public string get_mangonngu()
        {
            return mann;
        }          
        
        public int get_gia()
        {
            return gia;
        }

        public string get_manhaxuatban()
        {
            return manxb;
        }

        public int get_namxuaban()
        {
            return namxuatban;
        }

        public int get_lanxuatban()
        {
            return lanxuatban;
        }

        public string get_matacgia()
        {
            return matg;
        }

        #endregion
        public bool taomoisach()
        {
            Truyxuatdulieu txdl = new Truyxuatdulieu();
            if (txdl.thucthitruyvan("insert into sach values('"+masach+"','"+maloai+"','"+mann+"','"+manxb+"','"+mancc+"','"+mavitri+"',N'"+tensach+"','"+gia+"','"+namxuatban+"','"+lanxuatban+"')") == 1)
            {
                KetNoi.closeconnect();
                return true;
            }

            else
            {
                KetNoi.closeconnect();
                return false;
            }
        }

        public bool capnhatsach()
        {
            Truyxuatdulieu txdl = new Truyxuatdulieu();
            if (txdl.thucthitruyvan("update sach set TENSACH=N'" + tensach + "',MALOAISACH='" + maloai + "',MANGONNGU='" + mann + "',GIA='" + gia + "', MANCC='" + mancc + "',MAVT='" + mavitri + "',MANXB='"+ manxb+ "',NAMXUATBAN='" + namxuatban + "',LANXUATBAN='" + lanxuatban + "' where  MASACH='" + masach + "'") == 1)
            {
                KetNoi.closeconnect();
                return true;
            }
            else 
            {
                KetNoi.closeconnect();
                return false;
            }
        }

        public bool xoasach()
        {
            Truyxuatdulieu txdl = new Truyxuatdulieu();
            if (txdl.thucthitruyvan("delete from sach where MASACH='" + masach + "'") == 1)
            {
                KetNoi.closeconnect();
                return true;
            }
            else 
            {
                KetNoi.closeconnect();
                return false;
            }
        }

        public bool xoasangtac()
        {
            Truyxuatdulieu txdl = new Truyxuatdulieu();
            if (txdl.thucthitruyvan("delete from SANGTAC where MASACH='" + masach + "'") == 1)
            {
                KetNoi.closeconnect();
                return true;
            }
            else
            {
                KetNoi.closeconnect();
                return false;
            }
        }

        public bool taomoisangtac()
        {
            Truyxuatdulieu txdl = new Truyxuatdulieu();
            if (txdl.thucthitruyvan("insert into SANGTAC values('"+ masach + "','" +matg+"')") == 1)
            {
                KetNoi.closeconnect();
                return true;
            }
            else
            {
                KetNoi.closeconnect();
                return false;
            }
        }

        public bool capnhatsachtac()
        {
            Truyxuatdulieu txdl = new Truyxuatdulieu();
            if (txdl.thucthitruyvan("update SANGTAC set MATACGIA='"+matg+"' where MASACH='"+masach+"'")==1)
            {
                KetNoi.closeconnect();
                return true;
            }
            else
            {
                KetNoi.closeconnect();
                return false;
            }
        }
    }
}
